package chixing.day10.work;

public class EncryptionDecryption {
    // 如字符串 Welcome
    //    加密方法：
    //      将第一个字母调换到最后，然后每个字母加3
    // （1）实现加密，并测试
    // （2）给定某一加密后的字符串，并解密还原成初始字符串
    public static String encryption(String str) {
        char[] chars = str.toCharArray();
        char temp = chars[0];
        chars[0] = chars[chars.length - 1];
        chars[chars.length - 1] = temp;
        for (int i = 0; i < chars.length; i++) {
            chars[i] = (char) (chars[i] + 3);
        }
        return new String(chars);
    }
    public static String decryption(String str) {
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            chars[i] = (char) (chars[i] - 3);
        }

        char temp = chars[0];
        chars[0] = chars[chars.length - 1];
        chars[chars.length - 1] = temp;
        return new String(chars);
    }
    public static void main(String[] args) {
        String str = "Welcome";
        System.out.println(encryption(str));
        System.out.println(decryption(encryption(str)));
    }
}

